package runner

import "github.com/jinzhu/copier"

type Config struct {
	CheckInterval uint8    `json:"check_interval" toml:"check_interval"`
	Concurrent    uint8    `json:"concurrent" toml:"concurrent"`
	ListenAddress string   `json:"listen_address" toml:"listen_address"`
	Runners       []Runner `json:"runners" toml:"runners"`
}

type Runner struct {
	Environment []string          `json:"environment" toml:"environment"`
	Executor    string            `json:"executor" toml:"executor"`
	Name        string            `json:"name" toml:"name"`
	OutputLimit int               `json:"output_limit" toml:"output_limit"`
	Token       string            `json:"token" toml:"token"`
	Url         string            `json:"url" toml:"url"`
	Cache       map[string]string `json:"cache" toml:"cache"`
	Kubernetes  Kubernetes        `json:"kubernetes" toml:"kubernetes"`
}

func (r *Runner) DeepCopy() Runner {
	newRunner := Runner{}
	copier.Copy(&newRunner, &r)
	return newRunner
}

type Kubernetes struct {
	CaFile                         string            `json:"ca_file" toml:"ca_file"`
	CertFile                       string            `json:"cert_file" toml:"cert_file"`
	Host                           string            `json:"host" toml:"host"`
	KeyFile                        string            `json:"key_file" toml:"key_file"`
	Namespace                      string            `json:"namespace" toml:"namespace"`
	CpuLimit                       string            `json:"cpu_limit" toml:"cpu_limit"`
	CpuRequest                     string            `json:"cpu_request" toml:"cpu_request"`
	HelperImage                    string            `json:"helper_image" toml:"helper_image"`
	Image                          string            `json:"image" toml:"image"`
	MemoryLimit                    string            `json:"memory_limit" toml:"memory_limit"`
	MemoryRequest                  string            `json:"memory_request" toml:"memory_request"`
	NamespaceOverwriteAllowed      string            `json:"namespace_overwrite_allowed" toml:"namespace_overwrite_allowed"`
	Privileged                     bool              `json:"privileged" toml:"privileged"`
	PullPolicy                     string            `json:"pull_policy" toml:"pull_policy"`
	ServiceAccountOverwriteAllowed string            `json:"service_account_overwrite_allowed" toml:"service_account_overwrite_allowed"`
	NodeTolerations                map[string]string `json:"node_tolerations" toml:"node_tolerations"`
	Volumes                        Volumes           `json:"volumes" toml:"volumes"`
}

type Volumes struct {
	HostPath []HostPathVolume `json:"host_path" toml:"host_path"`
	PVC      []PVCVolume      `json:"pvc" toml:"pvc"`
}

type HostPathVolume struct {
	HostPath  string `json:"host_path" toml:"host_path"`
	MountPath string `json:"mount_path" toml:"mount_path"`
	Name      string `json:"name" toml:"name"`
}

type PVCVolume struct {
	Name      string `json:"name" toml:"name"`
	MountPath string `json:"mount_path" toml:"mount_path"`
	Readonly  bool   `json:"readonly" toml:"readonly"`
}
